class Solution
{
public:
    string decodeMessage(string key, string message)
    {
        vector<char> keyMap(26);
        int used = 0;
        int target = 'a';
        for (char c : key)
        {
            if (c == ' ')
            {
                continue;
            }
            if (!(used & (1 << (c - 'a'))))
            {
                keyMap[c - 'a'] = target;
                ++target;
                if (target > 'z')
                {
                    break;
                }
                used |= 1 << (c - 'a');
            }
        }
        for (char &m : message)
        {
            if (m != ' ')
            {
                m = keyMap[m - 'a'];
            }
        }
        return message;
    }
};